home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE10 / INTERNAL / UTEST.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-05-09  |  3.2 KB  |  127 lines

  1. unit Utest;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Format, StdCtrls, ExtCtrls, Gauges, DOSInfo;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     AbortButton: TButton;
  12.     Label2: TLabel;
  13.     Label3: TLabel;
  14.     WhichDrive: TComboBox;
  15.     SizeBox: TComboBox;
  16.     QuickFormat: TCheckBox;
  17.     LabelName: TEdit;
  18.     Label4: TLabel;
  19.     Gauge1: TGauge;
  20.     Panel1: TPanel;
  21.     FormatButton: TButton;
  22.     Label5: TLabel;
  23.     procedure FormatButtonClick(Sender: TObject);
  24.     procedure AbortButtonClick(Sender: TObject);
  25.     procedure FormCreate(Sender: TObject);
  26.     procedure WhichDriveChange(Sender: TObject);
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. procedure MyProgressHook (percent: Integer); far;
  41. begin
  42.     Form1.Gauge1.Progress := percent;
  43. end;
  44.  
  45. procedure TForm1.FormatButtonClick(Sender: TObject);
  46. var
  47.     err, sz: Integer;
  48.     str: String;
  49. begin
  50.     Progress := MyProgressHook;
  51.  
  52.     Screen.Cursor := crHourGlass;
  53.     AbortButton.Enabled := True;
  54.     FormatButton.Enabled := False;
  55.  
  56.     if QuickFormat.Checked then sz := -1
  57.     else sz := LongInt (SizeBox.Items.Objects [SizeBox.ItemIndex]);
  58.     err := FormatDisk (WhichDrive.ItemIndex + 1, sz);
  59.     Screen.Cursor := crDefault;
  60.  
  61.     if err <> 0 then
  62.     begin
  63.         str := SysUtils.Format ('Call to FormatDisk failed %d', [err]);
  64.         MessageDlg (str, mtError, [mbOK], 0);
  65.     end
  66.     else
  67.     begin
  68.         if LabelName.Text <> '' then
  69.             SetDriveLabel (WhichDrive.ItemIndex + 1, LabelName.Text);
  70.         MessageDlg ('Disk has been successfully formatted', mtInformation, [mbOK], 0);
  71.     end;
  72.  
  73.     Gauge1.Progress := 0;
  74.     AbortButton.Enabled := False;
  75.     FormatButton.Enabled := True;
  76. end;
  77.  
  78. procedure TForm1.AbortButtonClick(Sender: TObject);
  79. begin
  80.     fAbort := True;
  81. end;
  82.  
  83. procedure TForm1.FormCreate(Sender: TObject);
  84. const
  85.     DriveNames: array [0..1] of String [10] = ( 'Drive A:', 'Drive B:' );
  86. var
  87.     i: Integer;
  88. begin
  89.     { Initialise WhichDrive combo-box }
  90.     for i := 0 to GetFloppyDriveCount - 1 do
  91.         WhichDrive.Items.Add (DriveNames [i]);
  92.     WhichDrive.ItemIndex := 0;
  93.     WhichDriveChange (Sender);
  94. end;
  95.  
  96. procedure TForm1.WhichDriveChange(Sender: TObject);
  97. var
  98.     driveSize: Integer;
  99.  
  100.     procedure AddSize (start, stop: Integer);
  101.     const
  102.         Names: array [0..4] of String [15] = (
  103.                '360 KBytes', '1.2 MBytes', '720 KBytes',
  104.                '1.44 MBytes', '2.88 MBytes'   );
  105.     var
  106.         i: Integer;
  107.     begin
  108.         for i := start downto stop do
  109.             SizeBox.Items.AddObject (Names [i], TObject (i));
  110.     end;
  111.  
  112. begin
  113.     SizeBox.Items.Clear;
  114.     { Drive selection has changed - update SizeBox combo }
  115.     driveSize := GetFloppyDriveType (WhichDrive.ItemIndex);
  116.     case driveSize of
  117.         360:  { 360 KBytes  }  AddSize (0, 0);
  118.         1200: { 1.2 MBytes  }  AddSize (1, 0);
  119.         720:  { 720 KBytes  }  AddSize (2, 2);
  120.         1440: { 1.44 MBytes }  AddSize (3, 2);
  121.         2880: { 2.88 MBytes }  AddSize (4, 2);
  122.     end;
  123.     SizeBox.ItemIndex := 0;
  124. end;
  125.  
  126. end.
  127.